package cn.sc.allinpay.allfavour.base.connect.socket.connection;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import cn.sc.allinpay.allfavour.base.connect.socket.connectfactory.ConnectParameter;

/**
 * 通联通信
 * author：pany
 * on 2017/11/14 16:58
 */
public abstract class AllinpayConnection extends SocketConnection {

    @Override
    protected byte[] convertSendData(byte[] data) {
        return data;
    }

    @Override
    protected byte[] convertReceiveData(InputStream is) throws IOException {
        ByteArrayOutputStream response = null;
        try {
            response = new ByteArrayOutputStream();
            byte[] temp = new byte[1024];
            int len;
            while ((len = is.read(temp)) != -1) {
                response.write(temp, 0, len);
            }
            return response.toByteArray();
        } catch (IOException e) {
            throw new IOException();
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }
}
